<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Tacopie: tacopie::utils::thread_pool Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="tacopie_logo.jpg"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Tacopie
   &#160;<span id="projectnumber">3.0.0</span>
   </div>
   <div id="projectbrief">Tacopie is a TCP Client &amp; Server C++11 library.</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><b>tacopie</b></li><li class="navelem"><b>utils</b></li><li class="navelem"><a class="el" href="classtacopie_1_1utils_1_1thread__pool.html">thread_pool</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#pub-types">Public Types</a> &#124;
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="classtacopie_1_1utils_1_1thread__pool-members.html">List of all members</a>  </div>
  <div class="headertitle">
<div class="title">tacopie::utils::thread_pool Class Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p><code>#include &lt;<a class="el" href="thread__pool_8hpp_source.html">thread_pool.hpp</a>&gt;</code></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-types"></a>
Public Types</h2></td></tr>
<tr class="memitem:a8ae8886fdeaa8e5c0abad12626a47296"><td class="memItemLeft" align="right" valign="top">typedef std::function&lt; void()&gt;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classtacopie_1_1utils_1_1thread__pool.html#a8ae8886fdeaa8e5c0abad12626a47296">task_t</a></td></tr>
<tr class="separator:a8ae8886fdeaa8e5c0abad12626a47296"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:aa0068f000b8ecb21b2b0a0c50f77877c"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classtacopie_1_1utils_1_1thread__pool.html#aa0068f000b8ecb21b2b0a0c50f77877c">thread_pool</a> (std::size_t nb_threads)</td></tr>
<tr class="separator:aa0068f000b8ecb21b2b0a0c50f77877c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:accddfc6fad613b0c6d407028799abfc5"><td class="memItemLeft" align="right" valign="top"><a id="accddfc6fad613b0c6d407028799abfc5"></a>
&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classtacopie_1_1utils_1_1thread__pool.html#accddfc6fad613b0c6d407028799abfc5">~thread_pool</a> (void)</td></tr>
<tr class="memdesc:accddfc6fad613b0c6d407028799abfc5"><td class="mdescLeft">&#160;</td><td class="mdescRight">dtor <br /></td></tr>
<tr class="separator:accddfc6fad613b0c6d407028799abfc5"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a63a850c39d21058eda9d655bb7eff452"><td class="memItemLeft" align="right" valign="top"><a id="a63a850c39d21058eda9d655bb7eff452"></a>
&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classtacopie_1_1utils_1_1thread__pool.html#a63a850c39d21058eda9d655bb7eff452">thread_pool</a> (const <a class="el" href="classtacopie_1_1utils_1_1thread__pool.html">thread_pool</a> &amp;)=delete</td></tr>
<tr class="memdesc:a63a850c39d21058eda9d655bb7eff452"><td class="mdescLeft">&#160;</td><td class="mdescRight">copy ctor <br /></td></tr>
<tr class="separator:a63a850c39d21058eda9d655bb7eff452"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa0077461da4da6ba3f4dcac029351234"><td class="memItemLeft" align="right" valign="top"><a id="aa0077461da4da6ba3f4dcac029351234"></a>
<a class="el" href="classtacopie_1_1utils_1_1thread__pool.html">thread_pool</a> &amp;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classtacopie_1_1utils_1_1thread__pool.html#aa0077461da4da6ba3f4dcac029351234">operator=</a> (const <a class="el" href="classtacopie_1_1utils_1_1thread__pool.html">thread_pool</a> &amp;)=delete</td></tr>
<tr class="memdesc:aa0077461da4da6ba3f4dcac029351234"><td class="mdescLeft">&#160;</td><td class="mdescRight">assignment operator <br /></td></tr>
<tr class="separator:aa0077461da4da6ba3f4dcac029351234"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a450bee2b7b2cd0aa0bc3935c8adc9ace"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classtacopie_1_1utils_1_1thread__pool.html#a450bee2b7b2cd0aa0bc3935c8adc9ace">add_task</a> (const <a class="el" href="classtacopie_1_1utils_1_1thread__pool.html#a8ae8886fdeaa8e5c0abad12626a47296">task_t</a> &amp;task)</td></tr>
<tr class="separator:a450bee2b7b2cd0aa0bc3935c8adc9ace"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:afb7befd9fa5f1fbd44423fddc8cbc5d3"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classtacopie_1_1utils_1_1thread__pool.html">thread_pool</a> &amp;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classtacopie_1_1utils_1_1thread__pool.html#afb7befd9fa5f1fbd44423fddc8cbc5d3">operator&lt;&lt;</a> (const <a class="el" href="classtacopie_1_1utils_1_1thread__pool.html#a8ae8886fdeaa8e5c0abad12626a47296">task_t</a> &amp;task)</td></tr>
<tr class="separator:afb7befd9fa5f1fbd44423fddc8cbc5d3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a8874d7040d12fbe446519bc9f2bcff37"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classtacopie_1_1utils_1_1thread__pool.html#a8874d7040d12fbe446519bc9f2bcff37">stop</a> (void)</td></tr>
<tr class="separator:a8874d7040d12fbe446519bc9f2bcff37"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a77a647a75be188a5c5f83b922c061107"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classtacopie_1_1utils_1_1thread__pool.html#a77a647a75be188a5c5f83b922c061107">is_running</a> (void) const</td></tr>
<tr class="separator:a77a647a75be188a5c5f83b922c061107"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a7c7ae922cedff8fa323828ebb6dea829"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classtacopie_1_1utils_1_1thread__pool.html#a7c7ae922cedff8fa323828ebb6dea829">set_nb_threads</a> (std::size_t nb_threads)</td></tr>
<tr class="separator:a7c7ae922cedff8fa323828ebb6dea829"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>basic thread pool used to push async tasks from the <a class="el" href="classtacopie_1_1io__service.html">io_service</a> </p>
</div><h2 class="groupheader">Member Typedef Documentation</h2>
<a id="a8ae8886fdeaa8e5c0abad12626a47296"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a8ae8886fdeaa8e5c0abad12626a47296">&#9670;&nbsp;</a></span>task_t</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">typedef std::function&lt;void()&gt; <a class="el" href="classtacopie_1_1utils_1_1thread__pool.html#a8ae8886fdeaa8e5c0abad12626a47296">tacopie::utils::thread_pool::task_t</a></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>task typedef simply a callable taking no parameter </p>

</div>
</div>
<h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a id="aa0068f000b8ecb21b2b0a0c50f77877c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aa0068f000b8ecb21b2b0a0c50f77877c">&#9670;&nbsp;</a></span>thread_pool()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">tacopie::utils::thread_pool::thread_pool </td>
          <td>(</td>
          <td class="paramtype">std::size_t&#160;</td>
          <td class="paramname"><em>nb_threads</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">explicit</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>ctor created the worker thread that start working immediately</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">nb_threads</td><td>number of threads to start the thread pool </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a id="a450bee2b7b2cd0aa0bc3935c8adc9ace"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a450bee2b7b2cd0aa0bc3935c8adc9ace">&#9670;&nbsp;</a></span>add_task()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void tacopie::utils::thread_pool::add_task </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="classtacopie_1_1utils_1_1thread__pool.html#a8ae8886fdeaa8e5c0abad12626a47296">task_t</a> &amp;&#160;</td>
          <td class="paramname"><em>task</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>add tasks to thread pool task is enqueued and will be executed whenever all previously executed tasked have been executed (or are currently being executed)</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">task</td><td>task to be executed by the threadpool </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a77a647a75be188a5c5f83b922c061107"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a77a647a75be188a5c5f83b922c061107">&#9670;&nbsp;</a></span>is_running()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool tacopie::utils::thread_pool::is_running </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
</div><div class="memdoc">
<dl class="section return"><dt>Returns</dt><dd>whether the <a class="el" href="classtacopie_1_1utils_1_1thread__pool.html">thread_pool</a> is running or not </dd></dl>

</div>
</div>
<a id="afb7befd9fa5f1fbd44423fddc8cbc5d3"></a>
<h2 class="memtitle"><span class="permalink"><a href="#afb7befd9fa5f1fbd44423fddc8cbc5d3">&#9670;&nbsp;</a></span>operator<<()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classtacopie_1_1utils_1_1thread__pool.html">thread_pool</a>&amp; tacopie::utils::thread_pool::operator&lt;&lt; </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="classtacopie_1_1utils_1_1thread__pool.html#a8ae8886fdeaa8e5c0abad12626a47296">task_t</a> &amp;&#160;</td>
          <td class="paramname"><em>task</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>same as add_task</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">task</td><td>task to be executed by the threadpool </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>current instance </dd></dl>

</div>
</div>
<a id="a7c7ae922cedff8fa323828ebb6dea829"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a7c7ae922cedff8fa323828ebb6dea829">&#9670;&nbsp;</a></span>set_nb_threads()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void tacopie::utils::thread_pool::set_nb_threads </td>
          <td>(</td>
          <td class="paramtype">std::size_t&#160;</td>
          <td class="paramname"><em>nb_threads</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>reset the number of threads working in the thread pool this can be safely called at runtime and can be useful if you need to adjust the number of workers</p>
<p>this function returns immediately, but change might be applied in the background that is, increasing number of threads will spwan new threads directly from this function (but they may take a while to start) moreover, shrinking the number of threads can only be applied in the background to make sure to not stop some threads in the middle of their task</p>
<p>changing number of workers do not affect tasks to be executed and tasks currently being executed</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">nb_threads</td><td>number of threads </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a8874d7040d12fbe446519bc9f2bcff37"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a8874d7040d12fbe446519bc9f2bcff37">&#9670;&nbsp;</a></span>stop()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void tacopie::utils::thread_pool::stop </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>stop the thread pool and wait for workers completion if some tasks are pending, they won't be executed </p>

</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li>includes/tacopie/utils/<a class="el" href="thread__pool_8hpp_source.html">thread_pool.hpp</a></li>
</ul>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>
